package com.example.plat.controller;

import com.example.plat.enity.Activity;
import com.example.plat.enity.dto.ActivityCardDto;
import com.example.plat.service.MyActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.modelmapper.ModelMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;
import java.util.stream.Collectors;

@Api(description = "我的活动管理")
@RestController
@RequestMapping
public class MyActivityController {

    @Autowired
    ModelMapper mapper;

    @Autowired
    private MyActivityService service;

    @ApiOperation("获取用户发布的活动")
    @GetMapping("/myActivity")
    public ResponseEntity<List<ActivityCardDto>> getMyActivity(String userName) throws ParseException {
        List<Activity> myActivity = service.getMyActivity(userName);
        List<ActivityCardDto> dtos = myActivity.stream().map(u ->
                mapper.map(u, ActivityCardDto.class)
        ).collect(Collectors.toList());
        return ResponseEntity.ok(dtos);
    }

    @ApiOperation("获取用户参与的活动")
    @GetMapping("/joinActivity")
    public ResponseEntity<List<ActivityCardDto>> getJoinActivity(Long userId) throws ParseException {
        List<Activity> myActivity = service.getJoinActivity(userId);
        List<ActivityCardDto> dtos = myActivity.stream().map(u ->
                mapper.map(u, ActivityCardDto.class)
        ).collect(Collectors.toList());
        return ResponseEntity.ok(dtos);
    }

    @ApiOperation("获取用户收藏的活动")
    @GetMapping("/collect")
    public ResponseEntity<List<ActivityCardDto>> getCollection(@RequestParam Long userId){
        List<Activity> collection = service.getCollection(userId);
        List<ActivityCardDto> dtos = collection.stream().map(u ->
                mapper.map(u, ActivityCardDto.class)
        ).collect(Collectors.toList());
        return ResponseEntity.ok(dtos);
    }

    @ApiOperation("获取用户历史发布")
    @GetMapping("/historyPublish")
    public ResponseEntity<List<ActivityCardDto>> getHistoryPublish(@RequestParam String userName) throws ParseException {
        List<Activity> list = service.getHistoryPublish(userName);
        List<ActivityCardDto> dtos = list.stream().map(u ->
                mapper.map(u, ActivityCardDto.class)
        ).collect(Collectors.toList());
        return ResponseEntity.ok(dtos);
    }

    @ApiOperation("获取用户历史参与")
    @GetMapping("/historyJoin")
    public ResponseEntity<List<ActivityCardDto>> getHistoryJoin(@RequestParam Long userId) throws ParseException {
        List<Activity> list = service.getHistoryJoin(userId);
        List<ActivityCardDto> dtos = list.stream().map(u ->
                mapper.map(u, ActivityCardDto.class)
        ).collect(Collectors.toList());
        return ResponseEntity.ok(dtos);
    }
}
